package com.kdgc.power.gen;


import org.beetl.core.Template;
import org.beetl.sql.gen.BaseProject;
import org.beetl.sql.gen.Entity;
import org.beetl.sql.gen.SourceConfig;

import java.io.Writer;
import java.util.Arrays;

public class MapperSourceBuilder extends TemplateSourceBuilder {
    public static String mapperPath = "mapper.btl";
    String suffix = "Mapper";
    String child;

    public MapperSourceBuilder() {
        super("mapper");

    }


    public void generate(BaseProject project, SourceConfig config, Entity entity) {
        Template template = groupTemplate.getTemplate(mapperPath);
        String entityName = entity.getName();
        template.binding("className", entityName);
        template.binding("package", project.getBasePackage(this.name));
        //得到生成的entity的包
        String entityPkg = project.getBasePackage("entity");
        String entityHead =  entityPkg + "." +entityName;
        template.binding("imports", Arrays.asList(entityHead));
        Writer writer = project.getWriterByName(this.name, entity.getName() + this.suffix + ".java");
        template.renderTo(writer);
    }
}
